package cz.muni.fi.pa165.sme.client.panels;

import cz.muni.fi.pa165.sme.client.fo.BurnedCaloriesFO;
import cz.muni.fi.pa165.sme.client.fo.SportActivityFO;
import cz.muni.fi.pa165.sme.client.pages.TemplatePage;
import cz.muni.fi.pa165.sme.client.pages.burnedCalories.CaloriesAddPage;
import cz.muni.fi.pa165.sme.client.pages.burnedCalories.CaloriesListPage;
import cz.muni.fi.pa165.sme.client.pages.sportActivity.ActivityAddPage;
import cz.muni.fi.pa165.sme.client.pages.sportActivity.ActivityListPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.ResourceModel;

/**
 * @author jirankova
 */
public class ClientMenuPanel extends Panel {

	public ClientMenuPanel(String id) {
		super(id);

		//burned calories
		add(createLink(CaloriesListPage.class, "caloriesManagement", BurnedCaloriesFO.class).add(new Label("caloriesManagement", new ResourceModel(
				"menu.calories.management"))));
		add(createLink(CaloriesListPage.class, "caloriesList", BurnedCaloriesFO.class));
		add(createLink(CaloriesAddPage.class, "caloriesAdd", BurnedCaloriesFO.class));

		//sport activities
		add(createLink(ActivityListPage.class, "activityManagement", SportActivityFO.class).add(new Label("activityManagement", new ResourceModel(
				"menu.activity.management"))));
		add(createLink(ActivityListPage.class, "activityList", SportActivityFO.class));
		add(createLink(ActivityAddPage.class, "activityAdd", SportActivityFO.class));
	}

	/**
	 * Creates link fore the provided response page with the provided id and model class
	 * @param responsePage class of the response page
	 * @param linkId link wicket id
	 * @param linkClass model class of the link
	 * @param <T> link parameter class
	 * @param <S> response page parameter class
	 * @return link
	 */
	private <T, S extends TemplatePage> Link<T> createLink(final Class<S> responsePage, final String linkId, final Class<T> linkClass) {
		return new Link<T>(linkId) {
			@Override
			public void onClick() {
				setResponsePage(responsePage);
			}
		};
	}
}
